package com.tql.pandian.util;

import com.ruoyi.common.core.utils.StringUtils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CommonUtilHll {
    public static final String TABNAME_FOOD_REPORTDAY="tql_hll_shop_bill_food_reportDay";
    public static final String SHOPNAME_BY_USERID="SHOPNAME_BY_USERID";

    public static String Enabled_ShopsForHll="enabledShopsForHll";
    public static String splitString(String pandianCode, int i) {
       // String input = "20240110BU1010010024S1";
        if(null==pandianCode||pandianCode.length()<i)return null;
        String result = pandianCode.substring(0, i);
        return result;
    }

    public static String getKingdeeShopIdBySplitString(String pandianCode) {
        if(StringUtils.isNotEmpty(pandianCode) && pandianCode.contains("BU") && pandianCode.contains("S")) {
            int startIndex = pandianCode.indexOf("BU") + 2;
            int endIndex = pandianCode.indexOf("S");
            String result = pandianCode.substring(startIndex, endIndex);
            return result;
        } else {
            return null;
        }
    }

    public static int getCurrentMonth(Date nowDate){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(nowDate);
        return calendar.get(Calendar.MONTH) +1;
    }

    //返回年月
    public static String getMonthDate(Date dateTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        return sdf.format(dateTime);
    }

    //返回年月
    public static String getDayDate(Date dateTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(dateTime);
    }

    //返回年月
    public static String getDayDate(Long dateTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(dateTime);
    }

    //获取上一天 yyyy-MM-dd
    public static String getLastDay(Date date){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, -1);
        Date date2 = cal.getTime();
        SimpleDateFormat format2= new SimpleDateFormat("yyyy-MM-dd");
        return format2.format(date2);
    }
    public static int getMonth(String timeStr) throws ParseException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

            Date date = sdf.parse(timeStr);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int month = calendar.get(Calendar.MONTH) + 1; // 月份从0开始，所以需要加1
            return month;


    }
   /* //加法
    public static BigDecimal addDecimal(BigDecimal st1,BigDecimal st2){
        BigDecimal bignum3 = st1.add(st2);
        return  bignum3;
    }

    //减法
    public static BigDecimal subtractDecimal(BigDecimal st1,BigDecimal st2){
        BigDecimal bignum3 = st1.subtract(st2);
        return  bignum3;
    }

    //乘法
    public static BigDecimal multiplyDecimal(BigDecimal st1,BigDecimal st2){
        BigDecimal bignum3 = st1.multiply(st2);
        return  bignum3;
    }

    //除法
    public static BigDecimal divideDecimal(BigDecimal st1,BigDecimal st2){
        BigDecimal bignum3 = st1.divide(st2);
        return  bignum3;
    }*/

    public static void main(String[] args) {
        String str = "20240110BU1010010024S1";
        String result = getKingdeeShopIdBySplitString(str);
        System.out.println(result);
    }
}
